﻿/*-------------------------------------------------------------------------
* 命名空间: WaferSelectV3.Common/DetectedRuleHelper
* 类       名: DetectedRuleHelper
* 功      能:  TD
* 时      间:  2024-05-16 9:06:23
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using WaferSelectV3.Extensions;
using WaferSelectV3.Models;
using WaferSelectV3.Services;

namespace WaferSelectV3.Common
{
    public class DetectedRuleHelper
    {
        //检测规则,目前先按照比较笨的方式,就是把所有的规则都先加载进来.
        // Key对应的等级,比如1,2,3,4,5,6,7
        // Value对应的是其标准. 检测的时候从大到小进行筛选,以为要排序,所以等级用int来表示比较好.

        #region 1. PC3 3D工位数据检测规则
        /// <summary>
        /// 平均厚度检测规则  <1,"140,170"> 类似这种. 如果后面那个字符串是空,就默认认为这个是符合要求的.
        /// 如果这个检测想没有开启,这个字典的长度为0
        /// </summary>
        public static Dictionary<int, string> ThicknessAverRule = new Dictionary<int, string>();

        /// <summary>
        /// TTV检测规则 <1,"0,27">
        /// </summary>
        public static Dictionary<int, string> TTVRule = new Dictionary<int, string>();

        /// <summary>
        /// 线痕最大值 <1,"0,15">
        /// </summary>
        public static Dictionary<int, string> LineTraceMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 翘曲 <1,"0,40">
        /// </summary>
        public static Dictionary<int, string> WarpingRule = new Dictionary<int, string>();

        /// <summary>
        /// 最小厚度
        /// </summary>
        public static Dictionary<int, string> ThicknessMinRule = new Dictionary<int, string>();

        /// <summary>
        /// 最大厚度
        /// </summary>
        public static Dictionary<int, string> ThicknessMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 是否密集线痕
        /// </summary>
        public static Dictionary<int, string> IsDenseLineRule = new Dictionary<int, string>();

        /// <summary>
        /// 上线痕数量
        /// </summary>
        public static Dictionary<int, string> LineTraceUpNumRule = new Dictionary<int, string>();

        /// <summary>
        /// 上线痕数量最大值
        /// </summary>
        public static Dictionary<int, string> LineTraceUpMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 下线痕数量
        /// </summary>
        public static Dictionary<int, string> LineTraceDownNumRule = new Dictionary<int, string>();

        /// <summary>
        /// 下线痕数量最大值
        /// </summary>
        public static Dictionary<int, string> LineTraceDownMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 线痕数量
        /// </summary>
        public static Dictionary<int, string> LineTraceCountRule = new Dictionary<int, string>();

        /// <summary>
        /// 电阻率
        /// </summary>
        public static Dictionary<int, string> ResistivityAverRule = new Dictionary<int, string>();

        /// <summary>
        /// 电阻率最大值
        /// </summary>
        public static Dictionary<int, string> ResistivityMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 电阻率最小值
        /// </summary>
        public static Dictionary<int, string> ResistivityMinRule = new Dictionary<int, string>();
        #endregion

        #region 2. PC1尺寸工位等级分类规则

        /// <summary>
        /// 边长最大值
        /// </summary>
        public static Dictionary<int, string> LengthMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 边长最小值
        /// </summary>
        public static Dictionary<int, string> LengthMinRule = new Dictionary<int, string>();

        /// <summary>
        /// X边长
        /// </summary>
        public static Dictionary<int, string> LengthXRule = new Dictionary<int, string>();

        /// <summary>
        /// Y边长
        /// </summary>
        public static Dictionary<int, string> LengthYRule = new Dictionary<int, string>();

        /// <summary>
        /// 对角线左上右下
        /// </summary>
        public static Dictionary<int, string> DiagonalLeftStartRule = new Dictionary<int, string>();

        /// <summary>
        /// 对角线左下右上
        /// </summary>
        public static Dictionary<int, string> DialonalRightStartRule = new Dictionary<int, string>();

        /// <summary>
        /// 倒角最大值
        /// </summary>
        public static Dictionary<int, string> ChamferMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 倒角最小值
        /// </summary>
        public static Dictionary<int, string> ChamferMinRule = new Dictionary<int, string>();

        /// <summary>
        /// 上下平行度
        /// </summary>
        public static Dictionary<int, string> UpDownParallelRule = new Dictionary<int, string>();

        /// <summary>
        /// 左右平行度
        /// </summary>
        public static Dictionary<int, string> LeftRightParallelRule = new Dictionary<int, string>();

        /// <summary>
        /// 直角边最大值
        /// </summary>
        public static Dictionary<int, string> SquareLineMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 直角边最小值
        /// </summary>
        public static Dictionary<int, string> SquareLineMinRule = new Dictionary<int, string>();

        /// <summary>
        /// 垂直度最大值
        /// </summary>
        public static Dictionary<int, string> VerticalAngleMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// 垂直度最小值
        /// </summary>
        public static Dictionary<int, string> VerticalAngleMinRule = new Dictionary<int, string>();

        /// <summary>
        /// 左上倒角
        /// </summary>
        public static Dictionary<int, string> LeftTopCharmferRule = new Dictionary<int, string>();

        /// <summary>
        /// 右上倒角
        /// </summary>
        public static Dictionary<int, string> RightTopCharmferRule = new Dictionary<int, string>();

        /// <summary>
        /// 左下倒角
        /// </summary>
        public static Dictionary<int, string> LeftBottomCharmferRule = new Dictionary<int, string>();

        /// <summary>
        /// 右下倒角
        /// </summary>
        public static Dictionary<int, string> RightBottomCharmferRule = new Dictionary<int, string>();

        /// <summary>
        /// 左上角度
        /// </summary>
        public static Dictionary<int, string> LeftTopAngleRule = new Dictionary<int, string>();

        /// <summary>
        /// 右上角度
        /// </summary>
        public static Dictionary<int, string> RightTopAngleRule = new Dictionary<int, string>();

        /// <summary>
        /// 左下角度
        /// </summary>
        public static Dictionary<int, string> LeftBottomAngleRule = new Dictionary<int, string>();

        /// <summary>
        /// 右下角度
        /// </summary>
        public static Dictionary<int, string> RightBottomAngleRule = new Dictionary<int, string>();

        /// <summary>
        /// X边长最大值
        /// </summary>
        public static Dictionary<int, string> LengthXMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// X边长最小值
        /// </summary>
        public static Dictionary<int, string> LengthXMinRule = new Dictionary<int, string>();

        /// <summary>
        /// Y边长最大值
        /// </summary>
        public static Dictionary<int, string> LengthYMaxRule = new Dictionary<int, string>();

        /// <summary>
        /// Y边长最小值
        /// </summary>
        public static Dictionary<int, string> LengthYMinRule = new Dictionary<int, string>();
        #endregion

        #region 3. 崩边工作的检测Ruler

        /// <summary>
        /// 前崩边有无
        /// </summary>
        public static Dictionary<int, string> FrontEdgeBreakExistRule = new Dictionary<int, string>();

        /// <summary>
        /// 前崩边数量
        /// </summary>
        public static Dictionary<int, string> FrontEdgeBreakNumRule = new Dictionary<int, string>();

        /// <summary>
        /// 前崩边面积
        /// </summary>
        public static Dictionary<int, string> FrontEdgeBreakAreaRule = new Dictionary<int, string>();

        /// <summary>
        /// 后崩边有无
        /// </summary>
        public static Dictionary<int, string> BackEdgeBreakExistRule = new Dictionary<int, string>();

        /// <summary>
        /// 后崩边数量
        /// </summary>
        public static Dictionary<int, string> BackEdgeBreakNumRule = new Dictionary<int, string>();

        /// <summary>
        /// 后崩边面积
        /// </summary>
        public static Dictionary<int, string> BackEdgeBreakAreaRule = new Dictionary<int, string>();

        // <summary>
        /// 左崩边有无
        /// </summary>
        public static Dictionary<int, string> LeftEdgeBreakExistRule = new Dictionary<int, string>();

        // <summary>
        /// 左崩边数量
        /// </summary>
        public static Dictionary<int, string> LeftEdgeBreakNumRule = new Dictionary<int, string>();

        // <summary>
        /// 左表崩有无
        /// </summary>
        public static Dictionary<int, string> LeftSurfaceBreakExistRule = new Dictionary<int, string>();

        /// <summary>
        /// 左表崩数量
        /// </summary>
        public static Dictionary<int, string> LeftSurfaceBreakNumRule = new Dictionary<int, string>();


        /// <summary>
        /// 右崩边有无
        /// </summary>
        public static Dictionary<int, string> RightEdgeBreakExistRule = new Dictionary<int, string>();


        /// <summary>
        /// 右崩边数量
        /// </summary>
        public static Dictionary<int, string> RightEdgeBreakNumRule = new Dictionary<int, string>();

        /// <summary>
        /// 右表崩有无
        /// </summary>
        public static Dictionary<int, string> RightSurfaceBreakExistRule = new Dictionary<int, string>();

        /// <summary>
        /// 右表崩数量
        /// </summary>
        public static Dictionary<int, string> RightSurfaceBreakNumRule = new Dictionary<int, string>();


        #endregion

        #region 没有检测数据的工单中对应规则

        ///// <summary>
        ///// 孔洞数量 (目前PC视觉那里没有这条消息,所以这个规则加载的时候不加载)
        ///// </summary>
        //public static Dictionary<int, string> HoleNumRule = new Dictionary<int, string>();

        ///// <summary>
        ///// 孔洞有无 (目前PC视觉那里没有这条消息,所以这个规则加载的时候不加载)
        ///// </summary>
        //public static Dictionary<int, string> HoleExistRule = new Dictionary<int, string>();

        ///// <summary>
        ///// 脏污数量 (目前PC视觉那里没有这条消息,所以这个规则加载的时候不加载)
        ///// </summary>
        //public static Dictionary<int, string> SmudgeNumRule = new Dictionary<int, string>();

        ///// <summary>
        ///// 脏污有无(目前PC视觉那里没有这条消息,所以这个规则加载的时候不加载)
        ///// </summary>
        //public static Dictionary<int, string> SmudgeExistRule = new Dictionary<int, string>();

        #endregion

        #region 4. 脏污工位检测规则

        /// <summary>
        /// 上脏污有无
        /// </summary>
        public static Dictionary<int, string> SumdgeUpExistRule = new Dictionary<int, string>();

        /// <summary>
        /// 上脏污面积
        /// </summary>
        public static Dictionary<int, string> SumdgeUpAreaRule = new Dictionary<int, string>();

        /// <summary>
        /// 上脏污数量
        /// </summary>
        public static Dictionary<int, string> SumdgeUpNumRule = new Dictionary<int, string>();

        /// <summary>
        /// 上脏污是否反向
        /// </summary>
        public static Dictionary<int, string> SumdgeUpReverseRule = new Dictionary<int, string>();

        /// <summary>
        /// 上脏污缺口有无
        /// </summary>
        public static Dictionary<int, string> HoleExistUpRule = new Dictionary<int, string>();

        /// <summary>
        /// 上脏污穿孔有无
        /// </summary>
        public static Dictionary<int, string> SumdgeUpHoleExistRule = new Dictionary<int, string>();

        /// <summary>
        /// 下脏污面积
        /// </summary>
        public static Dictionary<int, string> SumdgeDownAreaRule = new Dictionary<int, string>();

        /// <summary>
        /// 下脏污数量
        /// </summary>
        public static Dictionary<int, string> SumdgeDownNumRule = new Dictionary<int, string>();

        /// <summary>
        /// 下脏污有无
        /// </summary>
        public static Dictionary<int, string> SumdgeDownExistRule = new Dictionary<int, string>();

        /// <summary>
        /// 下脏污穿孔有无
        /// </summary>
        public static Dictionary<int, string> SumdgeDownHoleExistRule = new Dictionary<int, string>();

        /// <summary>
        /// 下脏污是否反向
        /// </summary>
        public static Dictionary<int, string> SumdgeDownReverseRule = new Dictionary<int, string>();

        /// <summary>
        /// 下脏污缺口有无
        /// </summary>
        public static Dictionary<int, string> HoleExistDownRule = new Dictionary<int, string>();


        #endregion


        #region 5. 隐裂工位检测规则

        /// <summary>
        /// 隐裂1_隐裂面积
        /// </summary>
        public static Dictionary<int, string> SubfissureArea01Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂1_隐裂数量
        /// </summary>
        public static Dictionary<int, string> SubfissureNum01Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂1_隐裂有无
        /// </summary>
        public static Dictionary<int, string> SubfissureExist01Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂1_崩边面积
        /// </summary>
        public static Dictionary<int, string> SubfissureBreakArea01Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂1_崩边数量
        /// </summary>
        public static Dictionary<int, string> SubfissureBreakNum01Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂1_崩边有无
        /// </summary>
        public static Dictionary<int, string> SubfissureBreakExist01Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂1_孔洞数量
        /// </summary>
        public static Dictionary<int, string> SubfissureHoleNum01Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂1_孔洞有无
        /// </summary>
        public static Dictionary<int, string> SubfissureHoleExist01Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂2_隐裂面积
        /// </summary>
        public static Dictionary<int, string> SubfissureArea02Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂2_隐裂数量
        /// </summary>
        public static Dictionary<int, string> SubfissureNum02Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂2_隐裂有无
        /// </summary>
        public static Dictionary<int, string> SubfissureExist02Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂2_崩边面积
        /// </summary>
        public static Dictionary<int, string> SubfissureBreakArea02Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂2_崩边数量
        /// </summary>
        public static Dictionary<int, string> SubfissureBreakNum02Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂2_崩边有无
        /// </summary>
        public static Dictionary<int, string> SubfissureBreakExist02Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂2_孔洞数量
        /// </summary>
        public static Dictionary<int, string> SubfissureHoleNum02Rule = new Dictionary<int, string>();

        /// <summary>
        /// 隐裂2_孔洞有无
        /// </summary>
        public static Dictionary<int, string> SubfissureHoleExist02Rule = new Dictionary<int, string>();

        #endregion

        /// <summary>
        /// 默认检测都是关闭的.如果有打开的就将其打开就行.之前的旧工单需要这个功能,新工单不再需要这个功能.保留
        /// </summary>
        public static List<bool> RuleOpenOrClose = new List<bool>()
        {
            false, false, false, false, false,  false, false, false, false, false,   false,false,false,false,false,false,false,false,false,false,false
        };

        /// <summary>
        /// 加载规则到字典中去.
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        public static DataResult LoadRuleToDictionary(RecipeDectectedRuleModel model)
        {
            DataResult result = new DataResult();
            try
            {
                if (model.DetectedName!.Contains("ON/OFF"))
                {
                    if (model.Level01Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[0] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[0] = false;
                    }
                    if (model.Level02Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[1] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[1] = false;
                    }
                    if (model.Level03Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[2] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[2] = false;
                    }
                    if (model.Level04Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[3] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[3] = false;
                    }
                    if (model.Level05Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[4] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[4] = false;
                    }
                    if (model.Level06Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[5] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[5] = false;
                    }
                    if (model.Level07Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[6] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[6] = false;
                    }
                    if (model.Level08Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[7] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[7] = false;
                    }
                    if (model.Level09Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[8] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[8] = false;
                    }
                    if (model.Level10Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[9] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[9] = false;
                    }
                    if (model.Level11Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[10] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[10] = false;
                    }
                    if (model.Level12Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[11] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[11] = false;
                    }
                    if (model.Level13Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[12] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[12] = false;
                    }
                    if (model.Level14Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[13] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[13] = false;
                    }
                    if (model.Level15Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[14] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[14] = false;
                    }
                    if (model.Level16Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[15] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[15] = false;
                    }
                    if (model.Level17Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[16] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[16] = false;
                    }
                    if (model.Level18Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[17] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[17] = false;
                    }
                    if (model.Level19Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[18] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[18] = false;
                    }
                    if (model.Level20Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[19] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[19] = false;
                    }
                    if (model.Level21Val!.ToLower().Contains("true"))
                    {
                        RuleOpenOrClose[20] = true;
                    }
                    else
                    {
                        RuleOpenOrClose[20] = false;
                    }
                }
                else if (model.DetectedName!.Equals("平均厚度"))
                {
                    WriteRuleToDictionary(ThicknessAverRule, model);
                }
                else if (model.DetectedName!.Equals("TTV"))
                {
                    WriteRuleToDictionary(TTVRule, model);
                }
                else if (model.DetectedName!.Equals("线痕最大值"))
                {
                    WriteRuleToDictionary(LineTraceMaxRule, model);
                }
                else if (model.DetectedName!.Equals("翘曲"))
                {
                    WriteRuleToDictionary(WarpingRule, model);
                }
                else if (model.DetectedName!.Equals("最小厚度"))
                {
                    WriteRuleToDictionary(ThicknessMinRule, model);
                }
                else if (model.DetectedName!.Equals("最大厚度"))
                {
                    WriteRuleToDictionary(ThicknessMaxRule, model);
                }
                else if (model.DetectedName!.Equals("是否密集线痕"))
                {
                    WriteRuleToDictionary(IsDenseLineRule, model);
                }
                else if (model.DetectedName!.Equals("上线痕数量"))
                {
                    WriteRuleToDictionary(LineTraceUpNumRule, model);
                }
                else if (model.DetectedName!.Equals("上线痕数量最大值"))
                {
                    WriteRuleToDictionary(LineTraceUpMaxRule, model);
                }
                else if (model.DetectedName!.Equals("下线痕数量"))
                {
                    WriteRuleToDictionary(LineTraceDownNumRule, model);
                }
                else if (model.DetectedName!.Equals("下线痕数量最大值"))
                {
                    WriteRuleToDictionary(LineTraceDownMaxRule, model);
                }
                else if (model.DetectedName!.Equals("线痕数量"))
                {
                    WriteRuleToDictionary(LineTraceCountRule, model);
                }
                else if (model.DetectedName!.Equals("电阻率"))
                {
                    WriteRuleToDictionary(ResistivityAverRule, model);
                }
                else if (model.DetectedName!.Equals("电阻率最大值"))
                {
                    WriteRuleToDictionary(ResistivityMaxRule, model);
                }
                else if (model.DetectedName!.Equals("电阻率最小值"))
                {
                    WriteRuleToDictionary(ResistivityMinRule, model);
                }
                else if (model.DetectedName!.Equals("边长最大值"))
                {
                    WriteRuleToDictionary(LengthMaxRule, model);
                }
                else if (model.DetectedName!.Equals("边长最小值"))
                {
                    WriteRuleToDictionary(LengthMinRule, model);
                }
                else if (model.DetectedName!.Equals("X边长"))
                {
                    WriteRuleToDictionary(LengthXRule, model);
                }
                else if (model.DetectedName!.Equals("Y边长"))
                {
                    WriteRuleToDictionary(LengthYRule, model);
                }
                else if (model.DetectedName!.Equals("对角线左上右下"))
                {
                    WriteRuleToDictionary(DiagonalLeftStartRule, model);
                }
                else if (model.DetectedName!.Equals("对角线左下右上"))
                {
                    WriteRuleToDictionary(DialonalRightStartRule, model);
                }
                else if (model.DetectedName!.Equals("倒角最大值"))
                {
                    WriteRuleToDictionary(ChamferMaxRule, model);
                }
                else if (model.DetectedName!.Equals("倒角最小值"))
                {
                    WriteRuleToDictionary(ChamferMinRule, model);
                }
                else if (model.DetectedName!.Equals("上下平行度"))
                {
                    WriteRuleToDictionary(UpDownParallelRule, model);
                }
                else if (model.DetectedName!.Equals("左右平行度"))
                {
                    WriteRuleToDictionary(LeftRightParallelRule, model);
                }
                else if (model.DetectedName!.Equals("直角边最大值"))
                {
                    WriteRuleToDictionary(SquareLineMaxRule, model);
                }
                else if (model.DetectedName!.Equals("直角边最小值"))
                {
                    WriteRuleToDictionary(SquareLineMinRule, model);
                }
                else if (model.DetectedName!.Equals("垂直度最大值"))
                {
                    WriteRuleToDictionary(VerticalAngleMaxRule, model);
                }
                else if (model.DetectedName!.Equals("垂直度最小值"))
                {
                    WriteRuleToDictionary(VerticalAngleMinRule, model);
                }
                else if (model.DetectedName!.Equals("左上倒角"))
                {
                    WriteRuleToDictionary(LeftTopCharmferRule, model);
                }
                else if (model.DetectedName!.Equals("右上倒角"))
                {
                    WriteRuleToDictionary(RightTopCharmferRule, model);
                }
                else if (model.DetectedName!.Equals("左下倒角"))
                {
                    WriteRuleToDictionary(LeftBottomCharmferRule, model);
                }
                else if (model.DetectedName!.Equals("右下倒角"))
                {
                    WriteRuleToDictionary(RightBottomCharmferRule, model);
                }
                else if (model.DetectedName!.Equals("左上角度"))
                {
                    WriteRuleToDictionary(LeftTopAngleRule, model);
                }
                else if (model.DetectedName!.Equals("右上角度"))
                {
                    WriteRuleToDictionary(RightTopAngleRule, model);
                }
                else if (model.DetectedName!.Equals("左下角度"))
                {
                    WriteRuleToDictionary(LeftBottomAngleRule, model);
                }
                else if (model.DetectedName!.Equals("右下角度"))
                {
                    WriteRuleToDictionary(RightBottomAngleRule, model);
                }
                else if (model.DetectedName!.Equals("X边长最大值"))
                {
                    WriteRuleToDictionary(LengthXMaxRule, model);
                }
                else if (model.DetectedName!.Equals("X边长最小值"))
                {
                    WriteRuleToDictionary(LengthXMinRule, model);
                }
                else if (model.DetectedName!.Equals("Y边长最大值"))
                {
                    WriteRuleToDictionary(LengthYMaxRule, model);
                }
                else if (model.DetectedName!.Equals("Y边长最小值"))
                {
                    WriteRuleToDictionary(LengthYMinRule, model);
                }
                else if (model.DetectedName!.Equals("前崩边有无"))
                {
                    WriteRuleToDictionary(FrontEdgeBreakExistRule, model);
                }
                else if (model.DetectedName!.Equals("前崩边数量"))
                {
                    WriteRuleToDictionary(FrontEdgeBreakNumRule, model);
                }
                else if (model.DetectedName!.Equals("前崩边面积"))
                {
                    WriteRuleToDictionary(FrontEdgeBreakAreaRule, model);
                }
                else if (model.DetectedName!.Equals("后崩边有无"))
                {
                    WriteRuleToDictionary(BackEdgeBreakExistRule, model);
                }
                else if (model.DetectedName!.Equals("后崩边数量"))
                {
                    WriteRuleToDictionary(BackEdgeBreakNumRule, model);
                }
                else if (model.DetectedName!.Equals("后崩边面积"))
                {
                    WriteRuleToDictionary(BackEdgeBreakAreaRule, model);
                }
                else if (model.DetectedName!.Equals("左崩边有无"))
                {
                    WriteRuleToDictionary(LeftEdgeBreakExistRule, model);
                }
                else if (model.DetectedName!.Equals("左崩边数量"))
                {
                    WriteRuleToDictionary(LeftEdgeBreakNumRule, model);
                }
                else if (model.DetectedName!.Equals("左表崩有无"))
                {
                    WriteRuleToDictionary(LeftSurfaceBreakExistRule, model);
                }
                else if (model.DetectedName!.Equals("左表崩数量"))
                {
                    WriteRuleToDictionary(LeftSurfaceBreakNumRule, model);
                }
                else if (model.DetectedName!.Equals("右崩边有无"))
                {
                    WriteRuleToDictionary(RightEdgeBreakExistRule, model);
                }
                else if (model.DetectedName!.Equals("右崩边数量"))
                {
                    WriteRuleToDictionary(RightEdgeBreakNumRule, model);
                }
                else if (model.DetectedName!.Equals("右表崩有无"))
                {
                    WriteRuleToDictionary(RightSurfaceBreakExistRule, model);
                }
                else if (model.DetectedName!.Equals("右表崩数量"))
                {
                    WriteRuleToDictionary(RightSurfaceBreakNumRule, model);
                }
                else if (model.DetectedName!.Equals("上脏污有无"))
                {
                    WriteRuleToDictionary(SumdgeUpExistRule, model);
                }
                else if (model.DetectedName!.Equals("上脏污面积"))
                {
                    WriteRuleToDictionary(SumdgeUpAreaRule, model);
                }
                else if (model.DetectedName!.Equals("上脏污数量"))
                {
                    WriteRuleToDictionary(SumdgeUpNumRule, model);
                }
                else if (model.DetectedName!.Equals("上脏污是否反向"))
                {
                    WriteRuleToDictionary(SumdgeDownReverseRule, model);
                }
                else if (model.DetectedName!.Equals("上脏污穿孔有"))
                {
                    WriteRuleToDictionary(SumdgeUpHoleExistRule, model);
                }
                else if (model.DetectedName!.Equals("上脏污缺口有无"))
                {
                    WriteRuleToDictionary(HoleExistUpRule, model);
                }
                else if (model.DetectedName!.Equals("下脏污有无"))
                {
                    WriteRuleToDictionary(SumdgeDownExistRule, model);
                }
                else if (model.DetectedName!.Equals("下脏污面积"))
                {
                    WriteRuleToDictionary(SumdgeDownAreaRule, model);
                }
                else if (model.DetectedName!.Equals("下脏污数量"))
                {
                    WriteRuleToDictionary(SumdgeDownNumRule, model);
                }
                else if (model.DetectedName!.Equals("下脏污穿孔有无"))
                {
                    WriteRuleToDictionary(SumdgeDownHoleExistRule, model);
                }
                else if (model.DetectedName!.Equals("下脏污是否反向"))
                {
                    WriteRuleToDictionary(SumdgeDownReverseRule, model);
                }
                else if (model.DetectedName!.Equals("下脏污缺口有无"))
                {
                    WriteRuleToDictionary(HoleExistDownRule, model);
                }
                else if (model.DetectedName!.Equals("1隐裂面积"))
                {
                    WriteRuleToDictionary(SubfissureArea01Rule, model);
                }
                else if (model.DetectedName!.Equals("1隐裂数量"))
                {
                    WriteRuleToDictionary(SubfissureNum01Rule, model);
                }
                else if (model.DetectedName!.Equals("1隐裂有无"))
                {
                    WriteRuleToDictionary(SubfissureExist01Rule, model);
                }
                else if (model.DetectedName!.Equals("1崩边面积"))
                {
                    WriteRuleToDictionary(SubfissureBreakArea01Rule, model);
                }
                else if (model.DetectedName!.Equals("1崩边数量"))
                {
                    WriteRuleToDictionary(SubfissureBreakNum01Rule, model);
                }
                else if (model.DetectedName!.Equals("1崩边有无"))
                {
                    WriteRuleToDictionary(SubfissureBreakExist01Rule, model);
                }
                else if (model.DetectedName!.Equals("1孔洞数量"))
                {
                    WriteRuleToDictionary(SubfissureHoleNum01Rule, model);
                }
                else if (model.DetectedName!.Equals("1孔洞有无"))
                {
                    WriteRuleToDictionary(SubfissureHoleExist01Rule, model);
                }
                else if (model.DetectedName!.Equals("2隐裂面积"))
                {
                    WriteRuleToDictionary(SubfissureArea02Rule, model);
                }
                else if (model.DetectedName!.Equals("2隐裂数量"))
                {
                    WriteRuleToDictionary(SubfissureNum02Rule, model);
                }
                else if (model.DetectedName!.Equals("2隐裂有无"))
                {
                    WriteRuleToDictionary(SubfissureExist02Rule, model);
                }
                else if (model.DetectedName!.Equals("2崩边面积"))
                {
                    WriteRuleToDictionary(SubfissureBreakArea02Rule, model);
                }
                else if (model.DetectedName!.Equals("2崩边数量"))
                {
                    WriteRuleToDictionary(SubfissureBreakNum02Rule, model);
                }
                else if (model.DetectedName!.Equals("2崩边有无"))
                {
                    WriteRuleToDictionary(SubfissureBreakExist02Rule, model);
                }
                else if (model.DetectedName!.Equals("2孔洞数量"))
                {
                    WriteRuleToDictionary(SubfissureHoleNum02Rule, model);
                }
                else if (model.DetectedName!.Equals("2孔洞有无"))
                {
                    WriteRuleToDictionary(SubfissureHoleExist02Rule, model);
                }
                result.State = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.GetFullException();
            }
            return result;
        }

        private static void WriteRuleToDictionary(Dictionary<int, string> ruleDictionary, RecipeDectectedRuleModel model)
        {

            if (1 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[1] = model.Level01Val!;
            }
            if (2 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[2] = model.Level02Val!;
            }
            if (3 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[3] = model.Level03Val!;
            }
            if (4 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[4] = model.Level04Val!;
            }
            if (5 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[5] = model.Level05Val!;
            }
            if (6 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[6] = model.Level06Val!;
            }
            if (7 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[7] = model.Level07Val!;
            }
            if (8 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[8] = model.Level08Val!;
            }
            if (9 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[9] = model.Level09Val!;
            }
            if (10 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[10] = model.Level10Val!;
            }
            if (11 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[11] = model.Level11Val!;
            }
            if (12 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[12] = model.Level12Val!;
            }
            if (13 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[13] = model.Level13Val!;
            }
            if (14 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[14] = model.Level14Val!;
            }
            if (15 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[15] = model.Level15Val!;
            }
            if (16 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[16] = model.Level16Val!;
            }
            if (17 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[17] = model.Level17Val!;
            }
            if (18 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[18] = model.Level18Val!;
            }
            if (19 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[19] = model.Level19Val!;
            }
            if (20 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[20] = model.Level20Val!;
            }
            if (21 <= GlobalValues.NormalDetectedTotalCounts)
            {
                ruleDictionary[21] = model.Level21Val!;
            }

            //if (RuleOpenOrClose[0] && !string.IsNullOrEmpty(model.Level01Val!))
            //{
            //    ruleDictionary[1] = model.Level01Val!;
            //}
            //if (RuleOpenOrClose[1] && !string.IsNullOrEmpty(model.Level02Val!))
            //{
            //    ruleDictionary[2] = model.Level02Val!;
            //}
            //if (RuleOpenOrClose[2] && !string.IsNullOrEmpty(model.Level03Val!))
            //{
            //    ruleDictionary[3] = model.Level03Val!;
            //}
            //if (RuleOpenOrClose[3] && !string.IsNullOrEmpty(model.Level04Val!))
            //{
            //    ruleDictionary[4] = model.Level04Val!;
            //}
            //if (RuleOpenOrClose[3] && !string.IsNullOrEmpty(model.Level04Val!))
            //{
            //    ruleDictionary[4] = model.Level04Val!;
            //}
            //if (RuleOpenOrClose[4] && !string.IsNullOrEmpty(model.Level05Val!))
            //{
            //    ruleDictionary[5] = model.Level05Val!;
            //}
            //if (RuleOpenOrClose[5] && !string.IsNullOrEmpty(model.Level06Val!))
            //{
            //    ruleDictionary[6] = model.Level06Val!;
            //}
            //if (RuleOpenOrClose[6] && !string.IsNullOrEmpty(model.Level07Val!))
            //{
            //    ruleDictionary[7] = model.Level07Val!;
            //}
            //if (RuleOpenOrClose[7] && !string.IsNullOrEmpty(model.Level08Val!))
            //{
            //    ruleDictionary[8] = model.Level08Val!;
            //}
            //if (RuleOpenOrClose[8] && !string.IsNullOrEmpty(model.Level09Val!))
            //{
            //    ruleDictionary[9] = model.Level09Val!;
            //}
            //if (RuleOpenOrClose[9] && !string.IsNullOrEmpty(model.Level10Val!))
            //{
            //    ruleDictionary[10] = model.Level10Val!;
            //}
            //if (RuleOpenOrClose[10] && !string.IsNullOrEmpty(model.Level11Val!))
            //{
            //    ruleDictionary[11] = model.Level11Val!;
            //}
            //if (RuleOpenOrClose[11] && !string.IsNullOrEmpty(model.Level12Val!))
            //{
            //    ruleDictionary[12] = model.Level12Val!;
            //}
            //if (RuleOpenOrClose[12] && !string.IsNullOrEmpty(model.Level13Val!))
            //{
            //    ruleDictionary[13] = model.Level13Val!;
            //}
            //if (RuleOpenOrClose[13] && !string.IsNullOrEmpty(model.Level14Val!))
            //{
            //    ruleDictionary[14] = model.Level14Val!;
            //}
            //if (RuleOpenOrClose[14] && !string.IsNullOrEmpty(model.Level15Val!))
            //{
            //    ruleDictionary[15] = model.Level15Val!;
            //}
            //if (RuleOpenOrClose[15] && !string.IsNullOrEmpty(model.Level16Val!))
            //{
            //    ruleDictionary[16] = model.Level16Val!;
            //}
            //if (RuleOpenOrClose[16] && !string.IsNullOrEmpty(model.Level17Val!))
            //{
            //    ruleDictionary[17] = model.Level17Val!;
            //}
            //if (RuleOpenOrClose[17] && !string.IsNullOrEmpty(model.Level18Val!))
            //{
            //    ruleDictionary[18] = model.Level18Val!;
            //}
            //if (RuleOpenOrClose[18] && !string.IsNullOrEmpty(model.Level19Val!))
            //{
            //    ruleDictionary[19] = model.Level19Val!;
            //}
            //if (RuleOpenOrClose[19] && !string.IsNullOrEmpty(model.Level20Val!))
            //{
            //    ruleDictionary[20] = model.Level20Val!;
            //}
            //if (RuleOpenOrClose[20] && !string.IsNullOrEmpty(model.Level21Val!))
            //{
            //    ruleDictionary[21] = model.Level21Val!;
            //}
            // 如何去判断一个字典里面保存的全部是空字符串
            bool isEmpty = true;
            foreach (string var in ruleDictionary.Values)
            {
                if (!string.IsNullOrEmpty(var))
                {
                    isEmpty = false;
                }
            }
            if (isEmpty)
            {
                ruleDictionary.Clear();
            }

            // 将检测名称 和  检测的标准写到文本中去.
            string? ruleContent = model.DetectedName;
            if (ruleDictionary.Count == 0)
            {
                ruleContent += "    关闭";
            }
            else
            {
                foreach (KeyValuePair<int, string> pair in ruleDictionary)
                {
                    ruleContent += $"  {pair.Key}_({pair.Value})";
                }
            }
            FileOperateHelper.WriteToFileAppend(PathDirProvider.DetectedRulePath, ruleContent!);
        }

        /// <summary>
        /// 获取检测规则中的内容,从Excel表格中,每一行的数据内容使用List<string>来表示
        /// </summary>
        /// <param name="productionRecipePath">使用的工单路径</param>
        /// <returns></returns>
        public static DataResult<List<List<string>>> GetRecipeDetectedRuleContent(string productionRecipePath)
        {
            DataResult<List<List<string>>> result = new DataResult<List<List<string>>>();
            try
            {
                var ruleContentResult = ExcelHelper.ExcelToListStringByFilePath(productionRecipePath, sheetIndex: 0);
                return ruleContentResult;
            }
            catch (Exception ex)
            {
                result.Message = ex.GetFullException();
            }
            return result;
        }
    }
}
